mStrGrid; Version 1.0, 17.6.1996, Freeware, Albrecht Mengel, mengel@stat-econ.uni-kiel.de This is a component descending from TStringGrid with some new sorting and searching properties & methods: procedure InsertCols(where,howmuch:Integer); procedure InsertRows(where,howmuch:Integer); procedure DeleteCols(where,howmuch:Integer); procedure DeleteRows(where,howmuch:Integer); It does not matter if there are less rows/cols than you want to delete. procedure AddCol(contents:String; delimiter:Char); procedure AddRow(contents:String; delimiter:Char); The contents are splitted into the single cells by the delimiter function ModifyRow(which:integer; contents,delimiter:string):integer; Results in the number of columns function ModifyCol(which:integer; contents,delimiter:string):integer; Results in the number of rows The following properties control sorting and searching: property KeyType:(soString,soStringCaseSensitive,soNumeric) This is the kind, how the keys (and cells) are compared. If you work with soNumeric, all non numbers get the same value 0. As these zero values would flip in random order a (case insensitive) string sort is performed after. So, first come the negatives, then the strings, and thereafter the positives. property KeyPos:Integer; property KeyLen:Integer; Here you may define, which substring of the cells is used to comparision. (Default is KeyPos=1 & KeyLen=MaxInt) property UseFixed:(hfNot,hfSmart,hfYes); hfNot: The fixed rows/columns remain as they are (and are not used in searching) hfSmart: When sorting complete rows, the fixed columns are part of the rows and change their contents in the same manner as the rows are exchanged. The top row (fixed rows) remain intact. When sorting complete columns, the fixed rows change and the fixed columns not. When sorting (single) row/column, hfSmart protects the fixed part of the row/column. hfYes: All sorting includes the fixed columns and rows (as if they were set to 0) procedure SortCompleteColumns(KeyRow:integer); procedure SortCompleteRows(KeyCol:integer); procedure SortRow(ThisRow:integer); procedure SortCol(ThisCol:integer); procedure SortAllRows; The rows are sorted independand procedure SortAllCols; The columns are sorted independand Searching can be done with the fixed substrings of cells (set SearchSubstring=true and use KeyPos and KeyLen) or anywhere in the cells (SearchSubstring=false) property SearchSubstring:Boolean; function FindFirst(Key:String; RowWise:Boolean; VAR ResultCol,ResultRow:Integer):Boolean; Searches all cells, if UseFixed=hfYes or excludes the fixed cells, if UseFixed=hfNo. If UseFixed=hfSmart, then the fixed cols are used if searching rowwise or the fixed rows are used if not searching rowwise. All finding methods result in true, when a cell was found. If nothing found then ResultCol and ResultRow are set to -1. function FindFirstInRow(Key:String; searchRow:Integer; VAR ResultCol,ResultRow:Integer):Boolean; The same as FindFirst, but only one row is used for searching. UseFixed=hfSmart is here the same as hfNo. function FindFirstInCol(Key:String; searchCol:Integer; VAR ResultCol,ResultRow:Integer):Boolean; function FindNext(VAR ResultCol,ResultRow:Integer):Boolean; A sample searching program: if FindFirst('steven',true{rowwise},c,r) then repeat memo1.lines.add('Found in cells['+inttostr(c)+','+inttostr(r)+'] = "'+cells[c,r]+'"'); until not FindNext(c,r); File can be read to or written from the table as ASCII file. The second parameter is the column delimiter in every row. procedure LoadFromFile(FileName,ColSep:string); procedure SaveToFile(FileName,ColSep:String); The demo program has one odd property: if found something in the fixed parts of the grid, the fixed rows/cols are duplicated. (Because it is not allowed to set the cursor there to) The file mStrList is required for compilation. It contains a 'sister' of TStringList, which can sort in the above manner and is a complete copy of TStringList, which can be found in \source\vcl\GRIDS.PAS. But I had a problem with compiling it completely. If you are good in programming OOP / VCL then please have a look in mStrList.pas and help me fixing the problem. Until now all seems to work. To install mStrGrid: 1. Copy mStrGrid.* and mStrList.* to a directory for your special delphi components. 2. Select the Component: Install menu. 3. Click the Add button. 4. Click the Browse button. 5. Locate and select the mStrGrid.pas file 6. Click the Ok buttons to close all the dialogs. The Delphi component library DLL will be recompiled with the new mStrGrid component added to the Additional page of the component palette. Software development: Programming consumes time, and programmed components save time. If you like my components feel free to send me some acknowledgment. I accept post cards of your town, money or cheques (2$ up to 20$). This is a motivation for me to continue developing for you. If you have some ideas to improve mStrList, mStrGrid or any other component send me a message. The component is copyright (C) 1996, by Albrecht Mengel. You may give copies to others by copying the original, unmodified zip file. You may use this component in your own projects free of charge as long as those projects are public domain, freeware or shareware project. The author of mStrList and mStrGrid (A. Mengel) makes no warranty of any kind, expressed or implied, including without limitation any warranties of merchantability and/or fitness for a particular purpose. In no event will the author be liable to you for any additional damages, including any lost profits, lost savings, or other incidental or consequential damages arising from the use of, or inability to use, this software and its accompanying documentation, even if the author has been advised of the possibility of such damages. Albrecht Mengel, University of Kiel, Germany Institute for Statistics & Economics Olshausenstrasse 40-60, D-24098 Kiel Tel. +49-431-880-2424 Fax. +49-431-880-2673 Email: mengel@stat-econ.uni-kiel.de http://www.stat-econ.uni-kiel.de/pers/mengel.htm